﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace BibMan.model.database.Referencer {
    public class JabRefLoader {

        private String filename;

        public JabRefLoader(String filename) {
            this.filename = filename;
        }

        public JabLibrary Load() {
            XmlSerializer serializer = new XmlSerializer(typeof(JabLibrary));
            TextReader textReader = new StreamReader(filename);
            JabLibrary references = (JabLibrary)serializer.Deserialize(textReader);
            textReader.Close();
            return references;
        }

        public void Save(JabLibrary references) {
            XmlSerializer serializer = new XmlSerializer(typeof(JabLibrary));
            TextWriter textWriter = new StreamWriter(filename);
            serializer.Serialize(textWriter, references);
            textWriter.Close();
        }

    }
}
